package yh.core.util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.log4j.Logger;



public class PluginThread  extends Thread{ 
	private static Logger log = Logger.getLogger("com.yh.core.util");
    private String url=null;
    private String JSESSIONID=null;
    private String personId=null;
    private String person=null;
    
	public  PluginThread(String url,String JSESSIONID,String personId,String person){
		this.url=url;
		this.JSESSIONID=JSESSIONID;
		this.person=person;
		this.personId=personId;
	}
	public   String   inputStream2String   (InputStream   in)   throws   IOException   {
        StringBuffer   out   =   new   StringBuffer();
        byte[]   b   =   new   byte[4096];
        for   (int   n;   (n   =   in.read(b))   !=   -1;)   {
                out.append(new   String(b,   0,   n));
        }
        return   out.toString();
} 
	 public void run(){
		 CloseableHttpClient httpclient = HttpClients.createDefault();
		 try {
			 HttpGet get=new HttpGet(url);
			 url+="&personId="+personId+"&person="+person;
			 get.setHeader("Cookie", "JSESSIONID="+JSESSIONID);  
			 CloseableHttpResponse httpReponse=httpclient.execute(get);
//			 httpReponse.
			String resp=inputStream2String(httpReponse.getEntity().getContent());
			if(resp!=null && resp.equals("-100")){
				//执行的调用出现了运行时错误，可以进行相关日志记录
				log.info("执行的调用出现了运行时错误:"+"person:"+person+"**personId:"+personId+"**url:"+url);
			}
			 get.releaseConnection();
		}
		 catch (ClientProtocolException e) {
				e.printStackTrace();
				//其他异常
				log.info("执行的调用出现了ClientProtocolException错误:"+"person:"+person+"**personId:"+personId+"**url:"+url);
				
		} catch (IOException e) {
				//网络异常
				e.printStackTrace();
				log.info("执行的调用出现了网络异常:"+"person:"+person+"**personId:"+personId+"**url:"+url);
		}finally {
				try {
					httpclient.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
	 }

}